package com.financing.platform.web;

import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.financing.platform.dto.UserFeedBackDTO;
import com.financing.platform.service.IFpUserFeedBackService;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.util.Dict;

@Controller
public class FpUserFeedBackAction extends BaseAction{
	
	@Autowired
	private IFpUserFeedBackService fpUserFeedBackServiceImpl;
	
	@RequestMapping("/fpUserFeedBackList.shtml")
	public ModelAndView fpUserFeedBackList(HttpServletRequest request,
			HttpServletResponse response) {
			request.getSession().setAttribute(Dict.requestID, "fpUserFeedBackList.shtml");
			
			List<UserFeedBackDTO> list = Collections.emptyList();
			try {
				list = fpUserFeedBackServiceImpl.userFeedBackList();
			} catch (SQLException e) {
				log.error("query fp user feed back error!",e);
			}
			
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("userFeedBackList", list);
			return new ModelAndView("fpUserFeedBackList",resultMap);
	}
	
	@RequestMapping("/updateFpUserFeedBack.shtml")
	@ResponseBody
	public Map<?,?> updateFpUserFeedBack(HttpServletRequest request,
			HttpServletResponse response,UserFeedBackDTO userFeedBackDTO) {
			DTOdateSet.setUpdateInfo(userFeedBackDTO, request.getSession());
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put(Dict.result, Dict.result_success);
			//设置用户反馈意见状态为02:已读
			userFeedBackDTO.setStatus("02");
			try {
				fpUserFeedBackServiceImpl.updateUserFeedBack(userFeedBackDTO);
			} catch (SQLException e) {
				log.error("update user feed back status error!",e);
				resultMap.put(Dict.result, Dict.result_error);
			}
			return resultMap;
	}
}
